<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <title>周报管理</title>
    <!-- head 中 -->
    <link rel="stylesheet" href="https://cdn.bootcss.com/weui/1.1.2/style/weui.min.css">
    <link href="${ctxStatic}/plugin/jquery-weui/lib/weui.min.css" type="text/css" rel="stylesheet"/>
    <link href="${ctxStatic}/plugin/jquery-weui/css/jquery-weui.css" type="text/css" rel="stylesheet"/>
</head>
<body ontouchstart>
<div class="weui-cells weui-cells_form">
    <div class="weui-cell">
        <div class="weui-cell__hd"><label for="startTime" class="weui-label">开始时间</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" id="startTime" type="text">
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label for="endTime" class="weui-label">结束时间</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" id="endTime" type="text">
        </div>
    </div>
    <div class="weui-cells__title">周报内容</div>
    <div class="weui-cells weui-cells_form">
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <textarea id="content" class="weui-textarea" placeholder="请输入文本" rows="4"></textarea>
                <div class="weui-textarea-counter"><span>0</span>/500</div>
            </div>
        </div>
    </div>
</div>
<div style="text-align:center;">
    <a href="javascript:;" id="temp" class="weui-btn weui-btn_primary" style="margin: 10px">暂存</a>
    <a href="javascript:;" id="save" class="weui-btn weui-btn_primary" style="margin: 10px">保存</a>
</div>
<!-- body 最后 -->
<script src="${ctxStatic}/plugin/jquery-weui/lib/jquery-2.1.4.js"></script>
<script src="${ctxStatic}/plugin/jquery-weui/js/jquery-weui.js"></script>
<script src="${ctxStatic}/plugin/jquery-weui/lib/fastclick.js"></script>
<script>
    $(function () {
        FastClick.attach(document.body);
    });
</script>
<script>
    var id;
    var startTime;
    var endTime;
    $("#startTime").calendar({
        onChange: function (p, values, displayValues) {
            startTime = values[0];
            if (startTime != null && endTime != null) {
                if (startTime > endTime) {
                    $.toptip("开始日期不能小于结束日期", "error");
                    startTime = null;
                } else {
                    startTime = values[0];
                }
            }
        }
    });
    $("#endTime").calendar({
        onChange: function (p, values, displayValues) {
            endTime = values[0];
            if (startTime != null && endTime != null) {
                if (startTime > endTime) {
                    $.toptip("结束日期不能小于开始日期", "error");
                    endTime = null;
                } else {
                    endTime = values[0];
                }
            }
        }
    });
    $("#temp").click(function () {
        if (startTime != null && endTime != null) {
            if (startTime > endTime) {
                $.toptip("开始日期不能小于结束日期", "error");
            } else {
                save(0);
            }
        } else {
            $.toptip("开始日期或结束日期不能为空", "error");
        }

    })
    $("#save").click(function () {
        if (startTime != null && endTime != null) {
            if (startTime > endTime) {
                $.toptip("开始日期不能小于结束日期", "error");
            } else {
                save(1);
            }
        } else {
            $.toptip("开始日期或结束日期不能为空", "error");
        }
    })

    $.ajax({
        type: "GET",
        url: "${ctx}/report/weekReport/weChatForm",
        data: {},
        dataType: "json",
        success: function (data) {
            if (data.success) {
                id = data.body.weekReport.id;
                startTime = data.body.weekReport.startTime;
                endTime = data.body.weekReport.endTime;
                content = data.body.weekReport.content;
                $('#startTime').val(startTime);
                $('#endTime').val(endTime);
                $('#content').val(content);
            }

        }
    });
    function save(type) {
        var content = $("#content").val();
        $.ajax({
            type: "POST",
            url: "${ctx}/report/weekReport/weChatSave",
            data: {id: id, type: type, startTime: startTime, endTime: endTime, content: content},
            dataType: "json",
            success: function (data) {
                if (data.success) {
                    id = data.body.weekReport.id;
                    if (type == 1) {
                        $('#startTime').val("");
                        $('#endTime').val("");
                        $('#content').val("");
                        $.toast("保存成功！", "success");
                    } else {
                        $.toast("暂存成功！", "success");
                    }
                }

            }
        });
    }
</script>
</body>
</html>